package com.snopy.concurrency.methodstack;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author snopy
 * @version 1.0.0
 * @classname MethodStack
 * @description
 * @email 77912204@qq.com
 * @date 2022/06/22 15:14
 */
@Slf4j
public class MethodStack {
    Lock lock = new ReentrantLock();
    public static void main(String[] args) {
        MethodStack methodStack = new MethodStack();
        String s = methodStack.m1(1);
        System.out.println(s);
    }

    public String m1(int num){
        if (num == 0){
            num = 10;
        }
        int n =0;
        synchronized (this){
            log.info("m1内存？;{}", ClassLayout.parseInstance(this).toPrintable());
            log.info("m1内存？;{}", ClassLayout.parseClass(MethodStack.class).toPrintable());
            int num1 = 5;
            n =  ++num +num1;
        }
        log.info("m1内存？;{}", ClassLayout.parseInstance(this).toPrintable());
        return m2(n)+" 在围观";
    }
    public String m2(int num){
        lock.lock();
        String adress = " 二仙桥拉屎";
        String result = m3(adress)+num+"个人";
        lock.unlock();
        log.info("m2内存？;{}", ClassLayout.parseInstance(this).toPrintable());
        return result;
    }
    public synchronized String m3(String address){
        String name = "李二毛";
        log.info("m3内存？;{}", ClassLayout.parseInstance(this).toPrintable());
        log.info("m3内存？;{}", ClassLayout.parseClass(MethodStack.class).toPrintable());
        return m4(name)+" 在"+address;
    }
    public static synchronized String m4(String name){

        String m4 = "hello";
        log.info("m4内存？;{}", ClassLayout.parseClass(MethodStack.class).toPrintable());
        return m4+name;
    }
}
